// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import config from '@/config'
import Vue from 'vue'
import ViewUI from '_c/iview/index';
import App from './App'
import {router} from './router/index'
import store from './store'
import Icon from 'vue-awesome/components/Icon'

import util from '@/libs/util';
import hasPermission from '_c/directives/hasPermission';
import hasRole from '_c/directives/hasRole';
import waterMark from '_c/directives/watermark';
import VueStomp from "vue-stomp";
import VueLazyLoad from 'vue-lazyload';
import {
    bindEvent,
    checkHoliday,
    closeTab,
    convertCurrencyToChinese,
    currencyFormat,
    destoryEvent,
    fireEvent,
    getMenuParams,
    getPageParams,
    newTab,
    numberFormat,
    updatePageParams
} from "@/libs/tools";
import uploader from '_c/file-upload/vue-simple-uploader/index'

import '@babel/polyfill';
import i18n from "@/locale";
import RuiAuto from '_c/rui-auto'

import ('_c/iview/styles/rui-theme/'+_AFS_PROJECT_CONFIG.theme+'.less')
Vue.config.productionTip = false
Vue.use(VueLazyLoad, {
    error: require('./assets/img-error.png'),
    loading: require('./assets/loading.gif')
})
Vue.use(ViewUI,{
    size: 'small',
    i18n: (key, value) => i18n.t(key, value)
});
Vue.use(RuiAuto);
Vue.component('icon', Icon);
Vue.use(VueStomp);
Vue.use(hasPermission);
Vue.use(hasRole);
Vue.use(uploader)
Vue.use(waterMark)

Vue.prototype.afs={}
Vue.prototype.$config = config
Vue.prototype._baseUrl = config.getBaseUrl();
Vue.prototype.afs.newTab=newTab
Vue.prototype.afs.closeTab=closeTab
Vue.prototype.afs.getPageParams=getPageParams
Vue.prototype.afs.setPageParams=updatePageParams
Vue.prototype.afs.getMenuParams=getMenuParams
Vue.prototype.afs.afsOn=bindEvent
Vue.prototype.afs.afsEmit=fireEvent
Vue.prototype.afs.afsOff=destoryEvent
Vue.prototype.afs.checkHoliday=checkHoliday

Vue.prototype.currencyFormat = currencyFormat;
Vue.prototype.numberFormat = numberFormat;
Vue.prototype.convertCurrencyToChinese = convertCurrencyToChinese;
Vue.prototype.afs.downloadFile = (response)=>{
    let blob = new Blob([response.data])
    let downloadElement = document.createElement('a');
    let href = window.URL.createObjectURL(blob); //创建下载的链接
    downloadElement.href = href;
    let fileName = response.headers['content-disposition'];
    if (fileName&& fileName.split('filename=').length>1){
        fileName =  fileName.split('filename=')[1];
    } else{
        fileName = "下载文件"
    }
    downloadElement.download = decodeURI(fileName); //下载后文件名
    document.body.appendChild(downloadElement);
    downloadElement.click(); //点击下载
    document.body.removeChild(downloadElement); //下载完成移除元素
    window.URL.revokeObjectURL(href); //释放掉blob对象
}
/* eslint-disable no-new */
new Vue({
    el: '#app',
    router,
    i18n,
    store,
    render: h => h(App),
    data: {
        currentPageName: ''
    },
    created() {
        if(this.$route.query._link||this.$route.name==='sso'){

        }else{
            // 初始化菜单
            util.initSystem(this);
        }
    }
})
